var build = 'prod';

var gulp = require('gulp');
var ngAnnotate = require('gulp-ng-annotate');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var ngmin = require('gulp-ngmin');
var stripDebug = require('gulp-strip-debug');
var jshint = require('gulp-jshint');

var tasksArgs = {
    // configModuleJs: {
    //     taskName: 'configModuleJs',
    //     src: ['publish/' + build + '/config.js'],
    //     dest: 'www/js/',
    //     fileName: 'config.js',
    //     isJsHint: false
    // },
    jsModuleJs: {
        taskName: 'jsModuleJs',
        src: ['module-js/**/*.js', 'publish/' + build + '/config.js', 'main/index.js'],
        dest: 'www/js/',
        fileName: 'src.js',
        isJsHint: false
    }
};

var taskNames = [];

for (var key in tasksArgs) {
    var t = tasksArgs[key];
    taskNames.push(t.taskName);

    var doThings = [];
    if (t.isJsHint) {
        doThings.push('jshint');
    }
    doThings.push(t.taskName);

    //gulp.watch(t.src, doThings);
}

gulp.task('default', taskNames);

gulp.task('jshint', function () {
    return gulp.src('module-js/**')
        .pipe(jshint())
        .pipe(jshint.reporter('default'));
});

// gulp.task(tasksArgs.configModuleJs.taskName, function () {
//     return gulp.src(tasksArgs.configModuleJs.src)
//         .pipe(stripDebug())
//         .pipe(ngAnnotate())
//         .pipe(concat(tasksArgs.configModuleJs.fileName))
//         .pipe(gulp.dest(tasksArgs.configModuleJs.dest))
//
//         .pipe(ngmin({dynamic: false}))
//         .pipe(rename({suffix: '.min'}))
//         .pipe(uglify({outSourceMap: false}))
//         .pipe(gulp.dest(tasksArgs.configModuleJs.dest))
// });

gulp.task(tasksArgs.jsModuleJs.taskName, function () {
    return gulp.src(tasksArgs.jsModuleJs.src)
        .pipe(stripDebug())
        .pipe(ngAnnotate())
        .pipe(concat(tasksArgs.jsModuleJs.fileName))
        .pipe(gulp.dest(tasksArgs.jsModuleJs.dest))

        .pipe(ngmin({dynamic: false}))
        .pipe(rename({suffix: '.min'}))
        .pipe(uglify({outSourceMap: false}))
        .pipe(gulp.dest(tasksArgs.jsModuleJs.dest))
});